<%@page import="org.apache.struts2.components.Include"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>购物车结算</title>
	<link rel="stylesheet" href="css/bootstrap.css"></link>
	<link rel="stylesheet" href="css/style.css"></link>
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery.easydropdown.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<style>
		.men fieldset{
			margin:2% 10% 3% 10%
		}
		.price_show div{
			display:inline-block
		}
	</style>
  </head>
  
  <body>
  <%@include file="common/head.jsp"%>
  <div class="menu">
	</div>
    <div class="men">
    	<fieldset>
    		<legend>商品详情</legend>
    			<s:iterator value="goodForShow" id="seller">
			    		<fieldset>
					    	<legend>店铺: ${seller.key}</legend>
					    	
					    	<table>
        
					    		 <s:iterator value="#seller.value" id="good">
						    		<tr><td>商品名</td><td>${good.goods.goodsname}</td></tr>
						    		<tr><td>描述</td><td>${good.goods.remark}</td></tr>
						    		<tr><td>价格</td><td>${good.goods.price}元</td></tr>
						    		<tr><td>数量</td><td>${good.quantity}</td></tr>
						    		<tr><td>小计</td><td class="subtotal">${good.quantity * good.goods.price}</td></tr>
						    	</s:iterator>
					    	</table>
					    </fieldset>
				</s:iterator>
		    <fieldset>
		    	<legend>收货信息</legend>
		    	<form name="ordersInfo" action="payOrders.action" method="post">
		    		<input type="hidden" value="${session.awaitOrders}" name="awaitOrdersNo"/>
			    	<table>
			    		<tr height="50px">
			    			<td width="30%">收件人</td>
			    			<td><input type="text" name="receiver" id="receiver" value="${session.loginUser.name}"/>
							<span class="redstar">*</span></td>
						</tr>
			    		<tr height="50px"><td>地址</td>
						<td><!-- 配合插件使用的隐藏域 -->
							<input type="hidden" name="address" id="address" value="${session.loginUser.address}" />
							<span id="addressList">
								<select id="province"></select> 
								<select id="city"></select>
								<select id="district"></select>
								<span class="redstar">*</span>
							</span>
						</td>
						</tr>
						<tr height="50px">
							<td width="30%">详细地址</td>
							<td><input type="text" id="street"><span class="redstar">*</span></td>
						</tr>
			    		<tr height="50px">
				    		<td>手机/电话号码</td>
				    		<td><input type="text" name="phone" id="phone" value="${session.loginUser.phone}"/><span class="redstar">*</span></td>
			    		</tr>
			    	</table>
		    	</form>
		    </fieldset>
		    <div class="price_show" style="float:right;width:400px;">
		    	<div>总金额:</div>
		    	<div><h1 id="total"></h1><input type="hidden" name="newOrder.money"/></div>
		    	<div>元</div>
		    </div>
		    <div class="price_show" style="float:right;width:300px;">
		    	<input type="button" class="btn_form form input" value="确认付款" onclick="confirmPay()"/>
		    </div>
    	</fieldset>
	    
    </div>
	<script type="text/javascript">
		/* 初始化地址和处理地址格式下拉框的js */
		var addressId = "address";
		var selectId = "addressList";
		/* 控制下拉js 结束 */
		
		function confirmPay() {
			var address = getFormatAddress("province", "city", "district", "street");
			var phone = $("#phone").val();
			var receiver = $("#receiver").val();
			var province = $("#province").val();
			var city = $("#city").val();
			var street = $("#street").val();
			if (receiver.length<1||receiver.length>32) {
				alert("请输入不超过32字符的收件人");
				document.getElementById("receiver").focus();
				return false;
			}
			if (province.length<1) {
				alert("请输入收件省份");
				return false;
			}
			if (city.length<1) {
				alert("请输入收件城市");
				return false;
			}
			if (street.length<1||street.length>64) {
				alert("请输入不超过64位的收件详细地址");
				return false;
			}
			if (phone.length<1) {
				alert("请输入联系电话");
				document.getElementById("phone").focus();
				return false;
			}
			if (address == "" || phone == "" || receiver == ""||province == ""||city == ""||street == "") {
				alert("请填写完整收货人信息!");
			} else {
				$("form").submit();
			}

		}
		
		$(document).ready(function() {
			var total = 0;
			$(".subtotal").each(function() {
				total += parseFloat($(this).text());
			});
			$("#total").text(total.toFixed(2));
		});
	</script>
	<!-- 导入加载地址下拉栏所需js文件-->
	<script src="myAddress/js/distpicker.js" charset="utf-8"></script>
	<!-- 导入初始化地址和处理地址格式所需js文件-->
	<script src="myAddress/js/myAddress.js" charset="utf-8"></script>
	<%@include file="common/footer.jsp"%>
  </body>
</html>
